<template>
  <div class="page">
    <!-- 头部 -->
    <header class="header">
      <p class="pp">舌象报告 ( 仅供参考 )</p>
      <div class="tom">
        <img
          src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic2.zhimg.com%2F50%2Fv2-5405fd0b85bd96319399d4e5c63ebf42_hd.jpg&refer=http%3A%2F%2Fpic2.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1621084218&t=96bc6a306ad97e07a21b2d745b3f2f1b"
          alt=""
        />
        <div class="text">
          <p class="p1">灸友39087</p>
          <p class="p2">2020-03-12 12:30</p>
        </div>
      </div>
    </header>
    <div class="content">
      <div class="tab">
        <span @click="active = 1" :class="{ active: active == 1 }"
          >报告结果</span
        >
        <span @click="active = 2" :class="{ active: active == 2 }"
          >调理方案</span
        >
      </div>
      <!-- 报告结果 -->
      <ul v-if="active == 1">
        <li>
          <div class="tite">
            <span>{{ resp.data.main_visceral }}</span>
            <img :src="resp.data.user_tongue_image" />
          </div>
          <p>{{ resp.data.main_visceral_language }}</p>
        </li>
        <li>
          <div class="tite">
            <span>苔质</span>
            <img :src="url" />
          </div>
          <p>{{ resp.data.tongue_quality_language }}</p>
        </li>
        <li>
          <div class="tite">舌苔</div>
          <p>{{ resp.data.tongue_coating_language }}</p>
        </li>
        <!-- 特征症状 -->
        <li>
          <div v-for="(item, i) in resp.data.symptom_source" :key="i">
            <div>
              <span class="tite">特征结合舌象可能对应以下病症</span>
              <p id="ppp">{{ item.target_symptom }}</p>
            </div>
            <div>
              <span class="tite">常见症状</span>
              <p>{{ item.target_symptom_source }}</p>
            </div>
          </div>
        </li>
      </ul>
      <!-- 调理方案 -->
      <div v-else-if="active == 2" class="idea">
        <div v-for="(item, attr) in resp1" :key="attr" class="idea_bod">
          <div class="idea_tite" >
            <img :src="item.url" />
            <span>{{ item.broadHeading }}</span>
          </div>
          <div v-for="(item1, attr) in item.schemes" :key="attr" class="idea_min">
            <span @click="test2(item1)">{{ item1 }}</span>
          </div>
        </div>
      </div>
     
    </div>
    <!-- 方案详情弹窗 -->
    <van-popup
      v-model="show"
      closeable
      position="bottom"
      :style="{ height: '30%' }"
    >
      <h3 v-html="shows"></h3>
    </van-popup>
  </div>
</template>
<script>
import { getSchemeWithSymptom, nameCare_detail } from "../../utils/api";
export default {
  data() {
    return {
      active: 1,
      resp: {}, // 路由query传过来的返回数据
      resp1: [],
      url:JSON.parse(window.localStorage.getItem('files')),
      conditioning_data_img: [
        { url: require("../../assets/aa.jpg") },
        { url: require("../../assets/bb.jpg") },
        { url: require("../../assets/cc.jpg") },
      ],
      show: false,
      shows: "",
    };
  },
  created() {
    this.test();
    this.test1();
  },
  methods: {
    test() {
      const resp = JSON.parse(this.$route.query.resp);
      console.log("症状传过来的路由--------", resp);
      console.log(resp.data.symptom_source, 105);

      this.resp = resp;
      console.log("保存症状传过来的路由数据", this.resp);
    },
    async test1() {
      let res = await getSchemeWithSymptom({
        symptom: this.resp.data.target_symptom,
      });
      console.log(res.data.data,888)
      this.resp1 =
        res.data.data &&
        res.data.data.map((item, index) => ({
          ...item,
          ...this.conditioning_data_img[index],
        }));
    },
    async test2(a) {
      console.log("test2");
      let res = await nameCare_detail({
        name: a,
      });
      // console.log(res, 789);
      this.show = true;
      let strList = res.data.data.detail.replace(/【/g, "<br>【");
      this.shows = strList;
    },
  },
};
</script>
<style lang="less" scoped>
.page {
  background: rgb(250, 252, 251);
  #disease {
  }
  .idea {
    padding-top: 2rem;
    .idea_bod{
      margin-bottom: 20px;
    }
    .idea_tite {
      display: flex;
      align-items: center;
      img{
        height: 30px; width: 30px;
        margin-right: 5px;
      }
    }
    .idea_min {
      padding: 8px;
      display: inline-block;
      margin-top: 10px;
      
      span {
        color: green;
        padding: 10px;
        background-color: #f2f2f2;
      }
    }
  }
}
.header {
  background: rgb(3, 223, 197);
  color: #fff;
  padding: 0.4rem 0 1.8rem 0.4rem;
  .text {
    .p1 {
      padding: 0;
      margin-bottom: 10px;
    }
    p {
      text-align: left;
    }
  }
  .pp {
    padding: 15px 0;
    text-align: center;
    font-size: 18px;
  }
  .tom {
    display: flex;
    align-items: center;
  }
  img {
    width: 2rem;
    height: 2rem;
    border-radius: 2rem;
    border: 0.1rem solid rgb(3, 223, 197);
    margin-right: 0.3rem;
  }
  .p1 {
    padding-bottom: 0.4rem;
  }
}
.content {
  position: relative;
  top: -1rem;
  width: 9rem;
  margin: 0 auto;

  .tab {
    color: #606060;

    font-weight: bold;
    width: 100%;
    position: relative;
    span {
      width: 4.5rem;
      text-align: center;
      line-height: 1.4rem;
      height: 1.2rem;
      display: block;
      position: absolute;
      top: 0;
      background: rgb(242, 242, 242);
      &:first-child {
        left: 0;
        border-radius: 0.2rem 0 0 0;
        &.active {
          background: #fff;
          height: 1.8rem;
          top: -0.4rem;
          width: 4.54rem;
          line-height: 2.1rem;
          border-radius: 0;
          border-radius: 0.2rem 0.6rem 0 0;
          color: rgb(3, 223, 197);
        }
      }
      &:last-child {
        right: 0;
        border-radius: 0 0.2rem 0 0;
        &.active {
          background: #fff;
          height: 1.8rem;
          top: -0.4rem;
          width: 4.54rem;
          line-height: 2.1rem;
          border-radius: 0;
          border-radius: 0.6rem 0.2rem 0 0;
          color: rgb(3, 223, 197);
        }
      }
    }
  }
  ul {
    padding-top: 2rem;
    li:last-child{
      margin-top: 30px;
    }
    li {
      font-size: 0.28rem;
      margin-bottom: 0.4rem;
      border-bottom: 0.1rem solid #ececec;
      #ppp {
        background-color: rgb(2, 207, 128);
        border-radius: 10px;
        margin: 20px 0 40px 0;
        width: 150px;
        text-align: center;
        color: #ffffff;
      }
      color: #666;
      .tite {
        font-size: 0.4rem;
        font-weight: 400px;
        color: black;
        display: flex;
        align-items: center;
        img {
          width: 0.8rem;
          height: 0.8rem;
          margin-left: 0.1rem;
          border-radius: 50%;
        }
      }
      p {
        padding: 0.3rem;
      }
    }
  }
  .tips {
    text-align: center;
    color: red;
    padding-top: 2rem;
    padding-bottom: 0.2rem;
    font-size: 0.28rem;
  }
  .btn {
    width: 100%;
    height: 1rem;
    background: rgb(2, 207, 128);
    color: #fff;
    display: block;
    text-align: center;
    line-height: 1rem;
    border-radius: 1rem;
  }
}
</style>
